<?php
/**
 * Description of view Order Completed
 *
 * @author tuanbao
 */
?>
<?php if (Yii::app()->user->hasFlash('success')): ?>
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <?php echo Yii::app()->user->getFlash('success'); ?>
    </div>
<?php endif; ?>
<?php
echo $this->renderPartial('_order_info', array(
    'receipt' => $receipt,
));
?>
<?php if ($receipt): ?>
    <div class="row-fluid">
        <div class="box span12">
            <div class="box-header" data-original-title>
                <h2>
                    Order Item(s)
                </h2>            
            </div>
            <div class="box-content table-responsive">
                <table class="table table-bordered table-striped table-condensed" id="table-order">
                    <thead>
                    <th></th>
                    <th>Item</th>
                    <th>Employee/Commission To</th>
                    <th>Qty</th>
                    <th>List Price</th>
                    <th>Discount</th>
                    <th>Tax</th>
                    <th>Hotdeal</th>
                    <th>First Time</th>
                    <th>Final Price</th>
                    </thead>
                    <tbody>
                        <tr>
                            <td>
                                <a  href="#">
                                    <img src="<?php echo $receipt->order->service->getImageBySize(100, 100); ?>" /> 
                                </a>
                            </td>
                            <td>
                                <p class="f-weight"><?php echo $receipt->item_description ?></p>
                            </td>
                            <td>
                                <div>
                                    <?php foreach ($perform as $staff): ?>
                                        <?php
                                        $nameStaff = Users::getRecordByUkey($staff->staff_ukey);
                                        echo $nameStaff->name;
                                        ?><br/>
                                    <?php endforeach; ?>
                                </div>
                            </td>
                            <td>
                                <?php echo $receipt->qty ?>
                            </td>
                            <td>
                                $<?php echo $receipt->list_price ?>
                            </td>
                            <td>
                                <?php echo $receipt->discount . $receipt->discount_type ?>
                                <!--Kiểm tra nếu order này có sử dụng package-->
                                <?php
                                if ($receipt->order->packageOrder):
                                    $package    = $receipt->order->packageOrder->packageCustomer->package;
                                    $pack_price = $package->price / $package->limit;
                                    ?>
                                    <br><span class="text-success"><b>Package discount:&nbsp;
                                            <?php echo "-$$pack_price" ?></b></span><br>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span id="voi-order-tax-display">$<?php echo $receipt->tax; ?></span>
                            </td>
                            <td><?php echo '$' . $receipt->order->getHotdealPrice(); ?></td>
                            <td><?php echo '$' . $receipt->order->getFirstTimePrice(); ?></td>

                            <td><span id="voi-order-final">$<?php echo $receipt->final_price ?></span></td>
                        </tr>
                    </tbody>
                </table>
                <?php if ($receipt->order->retailOrder): ?>
                    <table class="table table-condensed">
                        <thead>
                        <th>Retail Item Name</th>
                        <th>Price</th>
                        <th>Quantity</th>
                        <th>Total</th>
                        </thead>
                        <tbody id="list_retail" class="form-horizontal">
                            <?php foreach ($receipt->order->retailOrder->items as $v): ?>
                                <tr>
                                    <td><?php echo $v->item->name ?></td>
                                    <td>$<?php echo $v->item->price ?></td>
                                    <td><?php echo $v->qty ?></td>
                                    <td>$<?php echo $v->qty * $v->item->price ?></td>
                                </tr>
                            <?php endforeach; ?>
                            <tr class="total_retail">
                                <td colspan="4">
                                    Discount &nbsp;<?php echo $receipt->order->retailOrder->receipt->discount ?>
                                    &nbsp;(<?php echo $receipt->order->retailOrder->receipt->discount_type == '$' ? 'Money' : 'Percent' ?>)
                                    <br>
                                    Tax:&nbsp;$<?php echo $receipt->order->retailOrder->receipt->tax ?>
                                </td>
                            </tr>
                            <tr class="total">
                                <td colspan="4">
                                    Total: $<?php echo $receipt->order->retailOrder->receipt->final_price ?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endif; ?>
<div id="receipt" class="hide">
    <?php
    echo $this->renderPartial('_receipt', array(
        'model'   => $receipt,
        'perform' => $perform,
        'payment' => $payment,
    ));
    ?>
</div>
<?php
echo $this->renderPartial('_payment_history', array(
    'payment' => $payment
));
